<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" layout:decorator="index">
<head>
<meta charset="UTF-8"/>
<title>Insert title here</title>

<!-- 引入 Bootstrap -->
   <link   href="../../../static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet"></link>
     <!--springboot默认路径-->
   <link href="bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet"></link>
<!--自己的样式-->
    <link href="location.css" rel="stylesheet"></link>
    <link href="../../../static/location.css" rel="stylesheet"></link>
   <!-- HTML5 Shiv 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
   <!-- 注意： 如果通过 file://  引入 Respond.js 文件，则该文件无法起效果 -->
   <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
   <![endif]-->
   <!-- jQuery (Bootstrap 的 JavaScript 插件需要引入 jQuery) -->
    <script src="https://code.jquery.com/jquery.js"></script>
    <!-- 包括所有已编译的插件 -->
    <script src="../../../static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <!--springboot默认路径-->
    <script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

    <script >
    //checkbox 全选/取消全选
           var isCheckAll = false;
           function swapCheck() {
               if (isCheckAll) {
                   $("input[type='checkbox']").each(function() {
                       this.checked = false;
                   });
                   isCheckAll = false;
               } else {
                   $("input[type='checkbox']").each(function() {
                       this.checked = true;
                   });
                   isCheckAll = true;
               }
    }



          function checkfatherid(checkedid){
            var objs = $("[ck='"+checkedid+"']");
            objs.each(function() {
                this.checked = true;
          });
        }
          function checkchildid(checkedid){
            var objs = $("[ck='"+checkedid+"']");
            objs.each(function() {
                this.checked = true;
          });

        }

    function selectparent(obj){
    			var ma = $(obj).attr("ma");

    			var objs = $("[parent='"+ma+"']");

    			if($(obj).prop("checked")){

            objs.each(function() {
                this.checked = true;
            });

    			}else{

            objs.each(function() {
                this.checked = false;
            });
    				}
    			}


    		function selectchild(obj){
    			var parent = $(obj).attr("parent");
    			var objs = $("[ma='"+parent+"']");
          console.log(objs);
    			if($(obj).prop("checked")){
            console.log(111);
            objs.each(function() {
                this.checked = true;
            });
    			}else{
    				var children =  $("[parent='"+parent+"']");
    				var bl = false;
            children.each(function() {
              console.log("children"+children);
              if($(this).prop("checked")){
                bl = true;

              }
            });
            console.log(bl);
    				if(!bl){
    					objs.removeAttr("checked");
    				}
    			}
    		}

    </script>


</head>

<body>
<div layout:fragment="content" class="content">
    <ol class="breadcrumb" th:object="${funplace}">
	  <li th:text="*{funplace1}"><a href="#" >系统管理</a></li>
	  <li th:text="*{funplace2}"><a href="#" >用户管理</a></li>
	  <li th:text="*{funplace3}" class="active" >用户添加</li>
 	</ol>
  <form class="form-horizontal" role="form" th:object="${role}" action="/role/updateRole" method="post">

          <div class="form-group">
            <label  class="col-sm-2 control-label"></label>
            <div class="col-lg-2">

              <input type="hidden"  th:value="*{id}" name="id" class="form-control"  id="firstname" placeholder="请输入用户名"/>
            </div>
          </div>

          <div class="form-group">
        		<label  class="col-sm-2 control-label">角色名称</label>
        		<div class="col-lg-2">

        			<input type="text"  th:value="*{rolename}" name="rolename" class="form-control" id="firstname" placeholder="请输入角色名"/>
            </div>
        	</div>

          <div class="form-group">
            <label  class="col-sm-2 control-label">角色简介</label>
            <div class="col-lg-2">

              <input type="text"  th:value="*{note}" name="note" class="form-control" id="firstname" placeholder="请输入角色简介"/>


            </div>
          </div>



          <div class="form-group">
              <label class="col-sm-2 control-label">是否超管</label>
              <div class="col-lg-2">
              <select class="form-control col-lg-2" name="ifadmin">
                  <option th:if="*{ifadmin==0}" th:value="0">普通用户</option>
                  <option th:if="*{ifadmin==1}" th:value="1">超级管理员</option>
                  <option  th:value="0">普通用户</option>
                  <option  th:value="1">超级管理员</option>

              </select>
              </div>
            </div>



              <div class="form-group">
                  <label class="col-sm-2 control-label">权限分配</label>
                  <div class="col-lg-2">
                      <input type="checkbox" id="inlineCheckbox1" value="option1" onclick="swapCheck()"/> 全选<br></br>
                    <span th:each="myfun : ${updatefunctions}">
                      <span th:if="${myfun.pid==0}">
                        <br></br>
                          <input type="checkbox" class="deleteid" onclick="selectparent(this)" th:attr="ck=${myfun.id},ma=${myfun.id}" ma="${myfun.id}"  name="ckid" value="1"   th:value="${myfun.id}" /><span th:text="'一级功能：'+${myfun.funname}+':'">功能名称：</span><br></br>
                          <span th:each="funcheck : *{funlist}">
                            <span th:if="${myfun.id==funcheck.id}">
                              <script th:inline="javascript">
                                  var checkedid = [[${funcheck.id}]];
                                  checkfatherid(checkedid);
                              </script>
                            </span>
                         </span>
                      </span>

                      <span th:each="sonfun : ${updatefunctions}">
                        <span th:if="${sonfun.pid==myfun.id}">

                            &nbsp;&nbsp;<input type="checkbox" class="deleteid" onclick="selectchild(this)" ck="*" th:attr="ck=${sonfun.id},parent=${myfun.id}" parent="${myfun.id}" name="ckid" value="1"   th:value="${sonfun.id}" /><span th:text="${sonfun.funname}">子功能</span>
                            <span th:each="funcheck : *{funlist}">
                              <span th:if="${sonfun.id==funcheck.id}">
                                <script th:inline="javascript">
                                    var checkedid = [[${funcheck.id}]];
                                    checkchildid(checkedid);
                                </script>
                              </span>
                           </span>
                        </span>

                      </span>
                    </span><br></br>


                  </div>
                </div>




        	<div class="form-group">
        		<div class="col-sm-offset-2 col-sm-10">
        			<button type="submit" class="btn btn-success" >添加</button>
              <button onclick="history.go(-1)" class="btn btn-warning" >返回</button>

        		</div>
        	</div>
</form>
</div>
</body>
</html>
